package com.ruoyi.environment.service.impl;

import cn.hutool.core.util.IdUtil;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.SecurityUtils;
import com.ruoyi.environment.domain.OpmEnvEmergeResp;
import com.ruoyi.environment.domain.OpmEnvRule;
import com.ruoyi.environment.mapper.OpmEnvEmergeRespMapper;
import com.ruoyi.environment.service.IOpmEnvEmergeRespService;
import com.ruoyi.system.api.LinkFileServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 应急处置Service业务层处理
 *
 * @author cjie
 * @date 2021-07-23
 */
@Service
public class OpmEnvEmergeRespServiceImpl extends LinkFileServiceImpl implements IOpmEnvEmergeRespService {
    @Autowired
    private OpmEnvEmergeRespMapper opmEnvEmergeRespMapper;

    /**
     * 查询应急处置
     *
     * @param id 应急处置ID
     * @return 应急处置
     */
    @Override
    public OpmEnvEmergeResp selectOpmEnvEmergeRespById(Long id) {
        OpmEnvEmergeResp result = opmEnvEmergeRespMapper.selectOpmEnvEmergeRespById(id);
        result.setFileList(getFileList(id.toString()));
        return result;
    }

    /**
     * 查询应急处置列表
     *
     * @param opmEnvEmergeResp 应急处置
     * @return 应急处置
     */
    @Override
    public List<OpmEnvEmergeResp> selectOpmEnvEmergeRespList(OpmEnvEmergeResp opmEnvEmergeResp) {
        return opmEnvEmergeRespMapper.selectOpmEnvEmergeRespList(opmEnvEmergeResp);
    }

    /**
     * 新增应急处置
     *
     * @param opmEnvEmergeResp 应急处置
     * @return 结果
     */
    @Override
    public int insertOpmEnvEmergeResp(OpmEnvEmergeResp opmEnvEmergeResp) {
        opmEnvEmergeResp.setId(IdUtil.getSnowflake(0, 0).nextId());
        opmEnvEmergeResp.setCreateTime(DateUtils.getNowDate());
        opmEnvEmergeResp.setCreateBy(SecurityUtils.getUsername());
        linkFile(opmEnvEmergeResp.getFileIdList(), opmEnvEmergeResp.getId().toString());
        return opmEnvEmergeRespMapper.insertOpmEnvEmergeResp(opmEnvEmergeResp);
    }

    /**
     * 修改应急处置
     *
     * @param opmEnvEmergeResp 应急处置
     * @return 结果
     */
    @Override
    public int updateOpmEnvEmergeResp(OpmEnvEmergeResp opmEnvEmergeResp) {
        opmEnvEmergeResp.setUpdateTime(DateUtils.getNowDate());
        opmEnvEmergeResp.setUpdateBy(SecurityUtils.getUsername());
        linkFile(opmEnvEmergeResp.getFileIdList(),Long.toString(opmEnvEmergeResp.getId()));
        return opmEnvEmergeRespMapper.updateOpmEnvEmergeResp(opmEnvEmergeResp);
    }

    /**
     * 批量删除应急处置
     *
     * @param ids 需要删除的应急处置ID
     * @return 结果
     */
    @Override
    public int deleteOpmEnvEmergeRespByIds(Long[] ids) {
        String[] res = new String[ids.length];
        for(int i=0;i<ids.length;i++){
            res[i] = String.valueOf(ids[i]);
        }
        deleteLinkFile(res);
        return opmEnvEmergeRespMapper.deleteOpmEnvEmergeRespByIds(ids);
    }

    /**
     * 删除应急处置信息
     *
     * @param id 应急处置ID
     * @return 结果
     */
    @Override
    public int deleteOpmEnvEmergeRespById(Long id) {
        return opmEnvEmergeRespMapper.deleteOpmEnvEmergeRespById(id);
    }
}
